package com.exercise.v1;


public class Expression {
    private int operand1;
    private int operand2;
    private String operator;
    private int result;

    public Expression() {
        this.operand1 = 0;
        this.operand2 = 0;
        this.operator = "+";
        this.result = 0;
    }

    public Expression(int operand1, int operand2, String operator) {
        this.operand1 = operand1;
        this.operand2 = operand2;
        this.operator = operator;
        this.result = calculate();
    }

    private int calculate() {
        switch (operator) {
            case "+":
                return operand1 + operand2;
            case "-":
                return operand1 - operand2;
            default:
                return 0;
        }
    }

    public int getOperand1() {
        return operand1;
    }

    public void setOperand1(int operand1) {
        this.operand1 = operand1;
        this.result = calculate();
    }

    public int getOperand2() {
        return operand2;
    }

    public void setOperand2(int operand2) {
        this.operand2 = operand2;
        this.result = calculate();
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
        this.result = calculate();
    }

    public int getResult() {
        return result;
    }
    public String toString() {
        return operand1 + " " + operator + " " + operand2 + " = " + result;
    }

    public String toQuestionString() {
        return operand1 + " " + operator + " " + operand2 + " = ?";
    }
}

